#include "Image.h"

N2F::Iw3D::Image::Image(const ScaleFactor &scaleFactor)
	: Element(scaleFactor)
{
	this->img = NULL;

	return;
}

N2F::Iw3D::Image::~Image()
{
	return;
}

const char *N2F::Iw3D::Image::getFile() const
{
	return(this->file);
}

void N2F::Iw3D::Image::setFile(const char *file)
{
	this->file = file;
	this->img = Iw2DCreateImage(file);
	this->img->GetMaterial()->SetFiltering(false);
	this->size = CIwFVec2(this->img->GetWidth(), this->img->GetHeight());

	return;
}

const CIw2DImage *N2F::Iw3D::Image::getImage() const
{
	return(this->img);
}

void N2F::Iw3D::Image::draw(int64 delta)
{
	CIwFVec2 s = this->translateSize();
	CIwFVec2 p = this->translatePosition();

	Iw2DDrawImage(this->img, p, s);

	return;
}

void N2F::Iw3D::Image::draw(int64 delta, CIwFVec2 offset)
{
	CIwFVec2 s = this->translateSize();
	CIwFVec2 p = this->translatePosition();
	p.x += (offset.x * this->scaleFactor.scale);
	p.y += (offset.y * this->scaleFactor.scale);

	Iw2DDrawImage(this->img, p, s);

	return;
}

void N2F::Iw3D::Image::draw(int64 delta, CIwFVec2 offset, float angle)
{
	CIwFVec2 s = this->translateSize();
	CIwFVec2 p = this->translatePosition();
	p.x += (offset.x * this->scaleFactor.scale);
	p.y += (offset.y * this->scaleFactor.scale);

	CIwFMat2D m = CIwFMat2D::g_Identity;
	m.Scale(this->scaleFactor.scale);
	m.SetRot(angle);
	m.ScaleRot(this->scaleFactor.scale);
	m.SetTrans(CIwFVec2((p.x + (s.x / 2)), (p.y + (s.y / 2))));

	Iw2DSetTransformMatrix(m);
	Iw2DDrawImage(this->img, CIwFVec2(-(s.x / 2), -(s.y / 2)), s);
	Iw2DSetTransformMatrix(CIwFMat2D::g_Identity);

	return;
}

void N2F::Iw3D::Image::draw(int64 delta, CIwFVec2 offset, float angle, float scale)
{
	CIwFVec2 s = this->translateSize(scale);
	CIwFVec2 p = this->translatePosition(scale);
	p.x += (offset.x * scale);
	p.y += (offset.y * scale);

	CIwFMat2D m = CIwFMat2D::g_Identity;
	m.Scale(scale);
	m.SetRot(angle);
	m.ScaleRot(scale);
	m.SetTrans(CIwFVec2((p.x + (s.x / 2)), (p.y + (s.y / 2))));

	Iw2DSetTransformMatrix(m);
	Iw2DDrawImage(this->img, CIwFVec2(-(s.x / 2), -(s.y / 2)), s);
	Iw2DSetTransformMatrix(CIwFMat2D::g_Identity);

	return;
}

void N2F::Iw3D::Image::OnKill()
{
	if (this->img != NULL)
	{
		delete this->img;
		this->img = NULL;
	}

	return;
}

bool N2F::Iw3D::Image::isHit(CIwFVec2 point)
{
	return(false);
}
